Jump to content

Testing Camera Capture

From RidgeRun Developer Wiki

Follow us on: YouTube Twitter LinkedIn Email Share this page

Share This Page






Problems running the pipelines shown on this page? Please see our GStreamer Debugging guide for help .

Camera Kernel Support

To test camera support on the Verdin i.MX95, we are going to use an OV5640 camera sensor. This is a CSI camera module from ARDUCAM. Some of the features of this camera sensor are:

  • Image Sensor: OV5640 from OmniVision
  • Still Resolution: 5Megapixels
  • Interface: MIPI CSI-2
  • Output Format: 8-/10-bit RGB RAW, RGB, YUV, JPEG
  • Max Pixel Array: 2592 x 1944 pixels
  • Sensor image area: 6.287mm x 4.712 mm (7.9mm diagonal)
  • Pixel Size 1.4μm x 1.4μm
  • Optical Size: 1/4"

Hardware setup

The camera should include a MIPI CSI cable. This cableis used to connect it to the Verdin Development board on port X47. The right connection and orientation of the cable is in the image below:

Fig 1. Camera connection on Verdin i.MX95 carrier board. Extracted from Toradex documentation

Here is how the sensor side should look:

Fig 1. Camera connection on Verdin i.MX95 carrier board. Extracted from Toradex documentation


Device Tree Overlay

The OV5640 is not part of the default NXP BSP, but can be integrated via a device tree overlay. The Reference Multimedia Image contains some device tree overlays. Among these overlays, there is one to support this camera sensor with a certain operation frequency. To enable it, modify the file '/boot/overlays.txt to have the following contents:

fdt_overlays=verdin-imx95_dsi-to-hdmi_overlay.dtbo verdin-imx95_spidev_overlay.dtbo verdin-imx95_ov5640-27mhz_overlay.dtbo

After modifying this file, reboot' the board to apply the verdin-imx95_ov5640-27mhz_overlay.dtbo overlay.

Capture Pipeline (Media Graph)

The i.MX95 uses the Media Controller framework to describe and configure the camera pipeline. This pipeline is composed of several interconnected hardware blocks such as the CSI receiver, formatter, crossbar, and ISI.

To visualize the pipeline, you can generate a graph using:

media-ctl --print-dot > graph.dot

The resulting graph.dot file contains the information to see the media graph. To watch the graph, you can copy this file to your host PC and run:

dot -Tpng graph.dot > graph.png

The resulting png file should show a graph like the following:

NXP i.MX95 example media pipeline graph

As you can see the link from the camera to the CSI module is a noncontinuous line. This means this link is not enabled. We are going to enable it in the following section:

Configure Media Pipeline

Minimal Required Setup

Only 3 commands are required:

1. Enable the link between the sensor and CSI receiver:

media-ctl -l "'ov5640 4-003c':0 -> 'csidev-4ad30000.csi':0 [1]"

2. Configure the sensor output format and resolution

media-ctl -V "'ov5640 4-003c':0 [fmt:UYVY8_1X16/1920x1080 field:none]"

3. Configure the capture device (/dev/videoX)

v4l2-ctl -d /dev/videoX -v width=1920,height=1080,pixelformat=YUYV


Note
These settings are not persistent. They must be applied after every reboot or automated using systemd.


Full Pipeline Configuration (Optional)

For non-default resolutions:

media-ctl -l "'ov5640 4-003c':0 -> 'csidev-4ad30000.csi':0 [1]"
media-ctl -V "'csidev-4ad30000.csi':0 [fmt:UYVY8_1X16/1280x720 field:none]"
media-ctl -V "'4ac10000.syscon:formatter@20':0 [fmt:UYVY8_1X16/1280x720 field:none]"
media-ctl -V "'crossbar':2 [fmt:UYVY8_1X16/1280x720 field:none]"
media-ctl -V "'mxc_isi.0':0 [fmt:UYVY8_1X16/1280x720 field:none]"

Capture Device

Available nodes:

/dev/video2 → mxc_isi.0.capture
/dev/video3 → mxc_isi.1.capture

Both /dev/video2 and /dev/video3 work.

Recommended:

/dev/video3

If the video capture above does not work, please review `graph.png` and check the node connected to `mxc_isi.output`. The capture device should correspond to that node.

For example, if `mxc_isi.output` points to node 4, the corresponding capture device may be `/dev/video6`.

Capture with v4l2-ctl

v4l2-ctl -d /dev/video3 --stream-mmap --stream-count=10 --stream-to=/tmp/out.yuyv
<<<<<<<<<<

Each '<' represents one captured frame.

GStreamer Pipelines

Display Camera

gst-launch-1.0 v4l2src device=/dev/video3 ! video/x-raw,format=YUY2,width=1920,height=1080,framerate=30/1 ! videoconvert ! waylandsink

Save Raw Video

gst-launch-1.0 v4l2src device=/dev/video3 num-buffers=100 ! video/x-raw,format=YUY2,width=1920,height=1080 ! filesink location=out.yuyv

Encode to MP4

gst-launch-1.0 -e v4l2src device=/dev/video3 ! video/x-raw,width=1920,height=1080 ! queue ! v4l2h264enc ! h264parse ! qtmux ! filesink location=output.mp4

Camera Capture with libcamera

In addition to direct V4L2 access, the camera can also be accessed through the libcamera framework. libcamera provides a higher-level abstraction layer that automatically discovers cameras, configures the media pipeline, manages capture requests, and exposes camera controls through a unified API.

On the i.MX95 platform, libcamera can be used either through its native applications or through the GStreamer libcamerasrc element. For detailed instructions, see Building libcamera on NXP i.MX95.





Cookies help us deliver our services. By using our services, you agree to our use of cookies.